package com.example.demo.mapper;

import com.example.demo.entity.InstrumentCollection;
import com.example.demo.entity.NotationCollection;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NotationCollectionMapper {
    // 添加收藏
    @Insert("INSERT INTO notation_collection_tb (user_id, notation_id, collection_date) " +
            "VALUES (#{user_id}, #{notation_id}, #{collection_date})")
    int addCollection(NotationCollection notationCollection);

    // 删除收藏
    @Delete("DELETE FROM notation_collection_tb WHERE user_id = #{user_id} AND notation_id = #{notation_id}")
    int deleteCollection(@Param("user_id") Integer userId, @Param("notation_id") Integer notationId);

    // 查询用户收藏的所有乐器
    @Select("SELECT c.*, i.name AS name, i.type AS type, i.cover_image AS image " +
            "FROM notation_collection_tb c " +
            "JOIN notation_tb i ON c.notation_id = i.notation_id " +
            "WHERE c.user_id = #{user_id}")
    List<NotationCollection> getCollectionsByUserId(@Param("user_id") Integer userId);

    // 检查用户是否收藏某个乐器
    @Select("SELECT COUNT(*) FROM notation_collection_tb WHERE user_id = #{user_id} AND notation_id = #{notation_id}")
    int checkIfCollected(@Param("user_id") Integer userId, @Param("notation_id") Integer notationId);

    //点击量(点击笔记浏览量)
    @Update("UPDATE notation_tb SET view_count = view_count + 1 WHERE notation_id = #{notation_id}")
    Integer incrementViewCount(@Param("notation_id") Integer notation_id);


}
